<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Description: 系统设置
 *
 * @author      Eden
 * @datetime    2016/11/26 21:43
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */

class About extends ADM_Controller
{

    /**
     * 初始化
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 首页
     */
    public function index()
    {
        $this->load->model('admin/system/Setting_Model', 'setting');
        $settings = $this->setting->get('system', array('aboutUs'));
        $this->load->view(parent::TMP_DIR . '/system/aboutus.html', array(
            'content' => value($settings, array('aboutUs', 'content'), '')
        ));
    }

    /**
     * 保存
     */
    public function save()
    {
        $send['state'] = false;
        do {

            if ($this->input->method(true) !== 'POST') {
                $send['error'] = '非法请求';
                break;
            }

            $params = $this->input->post();
            foreach($params as $key => $field) {
                if (!in_array($key, array('content', 'text'))) {
                    $send['error'] = '包含不合法的参数';
                    break 2;
                }
            }

            $this->load->model('admin/system/Setting_Model', 'm');
            if ($res = $this->m->save('aboutUs', $params)) {
                $send['state'] = true;
            } else {
                $send['error'] = '保存失败';
            }

        } while(false);
        $this->output->send($send);
    }
}
